...

Source file src/github.com/ory/fosite/access_response.go

Documentation: github.com/ory/fosite

     1  /*
     2   * Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   * @author		Aeneas Rekkas <aeneas+oss@aeneas.io>
    17   * @copyright 	2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
    18   * @license 	Apache-2.0
    19   *
    20   */
    21  
    22  package fosite
    23  
    24  import (
    25  	"strings"
    26  	"time"
    27  )
    28  
    29  func NewAccessResponse() *AccessResponse {
    30  	return &AccessResponse{
    31  		Extra: map[string]interface{}{},
    32  	}
    33  }
    34  
    35  type AccessResponse struct {
    36  	Extra       map[string]interface{}
    37  	AccessToken string
    38  	TokenType   string
    39  }
    40  
    41  func (a *AccessResponse) SetScopes(scopes Arguments) {
    42  	a.SetExtra("scope", strings.Join(scopes, " "))
    43  }
    44  
    45  func (a *AccessResponse) SetExpiresIn(expiresIn time.Duration) {
    46  	a.SetExtra("expires_in", int64(expiresIn/time.Second))
    47  }
    48  
    49  func (a *AccessResponse) SetExtra(key string, value interface{}) {
    50  	a.Extra[key] = value
    51  }
    52  
    53  func (a *AccessResponse) GetExtra(key string) interface{} {
    54  	return a.Extra[key]
    55  }
    56  
    57  func (a *AccessResponse) SetAccessToken(token string) {
    58  	a.AccessToken = token
    59  }
    60  
    61  func (a *AccessResponse) SetTokenType(name string) {
    62  	a.TokenType = name
    63  }
    64  
    65  func (a *AccessResponse) GetAccessToken() string {
    66  	return a.AccessToken
    67  }
    68  
    69  func (a *AccessResponse) GetTokenType() string {
    70  	return a.TokenType
    71  }
    72  
    73  func (a *AccessResponse) ToMap() map[string]interface{} {
    74  	a.Extra["access_token"] = a.GetAccessToken()
    75  	a.Extra["token_type"] = a.GetTokenType()
    76  	return a.Extra
    77  }
    78  

View as plain text