mirror of
				https://github.com/OpenAPITools/openapi-generator.git
				synced 2025-11-04 10:43:44 +00:00 
			
		
		
		
	[Dart] Allow setting an accessToken for OAuth (#7528)
* dart - allow setting an accessToken for oauth * Remove unneeded accessToken member
This commit is contained in:
		
							parent
							
								
									eb35870d11
								
							
						
					
					
						commit
						f1638a659a
					
				@ -153,4 +153,12 @@ class ApiClient {
 | 
			
		||||
      auth.applyToParams(queryParams, headerParams);
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void setAccessToken(String accessToken) {
 | 
			
		||||
    _authentications.forEach((key, auth) {
 | 
			
		||||
      if (auth is OAuth) {
 | 
			
		||||
        auth.setAccessToken(accessToken);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,19 @@
 | 
			
		||||
part of {{pubName}}.api;
 | 
			
		||||
 | 
			
		||||
class OAuth implements Authentication {
 | 
			
		||||
  String accessToken;
 | 
			
		||||
 | 
			
		||||
  OAuth({this.accessToken}) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
 | 
			
		||||
    // TODO: support oauth
 | 
			
		||||
    if (accessToken != null) {
 | 
			
		||||
      headerParams["Authorization"] = "Bearer " + accessToken;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void setAccessToken(String accessToken) {
 | 
			
		||||
    this.accessToken = accessToken;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user